浏览量 4434
2016/03/31 13:17
示例:点击 -> 性能监控
[root@wangzi go]# cat /proc/stat
cpu 25187586 4339 20108620 1703341684 3875717 0 58452 0 0 0
pytho代码:
#!/usr/bin/env python
# coding=utf-8
# author: brownwang
# mail: 277215243@qq.com
# datetime:2019/3/31 1:03 PM
# web: https://www.bthlt.com
def cpu_use():
use=0
with open('/proc/stat','r') as file:
for line in file.readlines():
if line.startswith('cpu ',0,4):
use=round((1-float(line.split()[4])/sum([int(x) for x in line.split()[1:]]))*100,5)
insert_sql="""insert into `monitor_cpu_use` (`use`,`flow_time`) values ({0},'{1}')""".format(use,now_zero)
cursorUpdate(insert_sql,[])
上一篇 搜索 下一篇